function [positionsOut, atomsOut] = sort_atoms_by_type(positions, atoms)
%SORT_ATOMS_BY_TYPE Summary of this function goes here
%   Detailed explanation goes here

atomTypes = unique(atoms);
numAtomTypes = length(atomTypes);

positionsOut = zeros(size(positions, 1), size(positions, 2));
atomsOut = cell(size(atoms, 1), size(atoms, 2));

numIndexTotal = 0;

for i = 1:numAtomTypes

  index = find(strcmp(atoms, atomTypes(i)));
  numIndex = length(index);
  positionsOut(numIndexTotal+1:numIndexTotal+numIndex, :) = positions(index, :);
  atomsOut(numIndexTotal+1:numIndexTotal+numIndex) = atoms(index);
  numIndexTotal = numIndexTotal + numIndex;
end



end

